package com.wushi.lenovo.asia5b.app_ui.other.dialog.pay;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.mvp.base.BaseDialog;
import com.mvp.base.model.ResultModel;
import com.wushi.lenovo.asia5b.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 支付后返回给界面看的
 */
public class PayResultDialog extends BaseDialog {
    @BindView(R.id.iv_payresult_icon)
    ImageView iv_payresult_icon;
    @BindView(R.id.tv_payresult_title)
    TextView tv_payresult_title;
    @BindView(R.id.tv_payresult_content)
    TextView tv_payresult_content;
    @BindView(R.id.bt_payresult_ok)
    Button bt_payresult_ok;
    private final ResultModel resultModel;
    private boolean isOrderPay = false;

    public PayResultDialog(Context context, ResultModel resultModel, boolean isOrderPay) {
        super(context);
        this.resultModel = resultModel;
        this.isOrderPay = isOrderPay;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_payresult;
    }

    @Override
    protected void initView() {
        String failuretitle = "";
        String failureContent = "";
        String successtitle = "";
        String successContent = "";
        if (isOrderPay) {
            failuretitle = getString(R.string.pay_failedtitle);
            if (TextUtils.isEmpty(resultModel.getMsg())) {
                failureContent = getString(R.string.pay_failedcontent);
            } else {
                failureContent = resultModel.getMsg();
            }
            successtitle = getString(R.string.pay_successtitle);
            if (TextUtils.isEmpty(resultModel.getMsg())) {
                successContent = getString(R.string.pay_successcontent);
            } else {
                successContent = resultModel.getMsg();
            }
        } else {
            failuretitle = getString(R.string.topup_fpx_trans_no1);
            if (TextUtils.isEmpty(resultModel.getMsg())) {
                failureContent = getString(R.string.topup_fpx_trans_no2);
            }else{
                failureContent = resultModel.getMsg();
            }
            successtitle = getString(R.string.topup_fpx_trans_yes1);
            if (TextUtils.isEmpty(resultModel.getMsg())) {
                successContent = getString(R.string.topup_fpx_trans_yes2);
            }else {
                successContent = resultModel.getMsg();
            }
        }
        if (resultModel.isSuccess()) {//成功
            iv_payresult_icon.setImageResource(R.drawable.icon_duigou2);
            tv_payresult_title.setText(successtitle);
            tv_payresult_content.setText(successContent);
        } else {//失败
            iv_payresult_icon.setImageResource(R.drawable.icon_error);
            tv_payresult_title.setText(failuretitle);
            tv_payresult_content.setText(failureContent);
        }
    }

    @OnClick({R.id.bt_payresult_ok})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_payresult_ok: {
                dismiss();
            }
            break;
            default:
                break;
        }

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @Override
    protected int getWidthStyle() {
        return getScreenWidth(0.8f);
    }

    @Override
    protected int getHeightStyle() {
        return WindowManager.LayoutParams.WRAP_CONTENT;
    }
}
